#include "HelloWorldScene.h"


USING_NS_CC;
#define UseSpriteFrame(_String_) Sprite::createWithSpriteFrameName(_String_)


Scene* HelloWorld::createScene()
{
    return HelloWorld::create();
}

// on "init" you need to initialize your instance
bool HelloWorld::init()
{
		int _map[MAP_W][MAP_H] = {
			{ 0,4,3,0,0,0 },
			{ 0,0,0,0,0,0 },
			{ 0,3,3,3,0,3 },
			{ 0,0,0,3,0,3 },
			{ 3,0,0,0,0,0 },
			{ 0,0,3,0,3,0 },
			{ 0,0,0,0,0,0 },
			{ 0,3,3,5,0,3 },
		};
		std::map<int, Color4B> mode;
		mode[0] = Color4B::WHITE;
		mode[3] = Color4B::BLUE;
		mode[4] = Color4B::BLACK;
		mode[5] = Color4B::RED;
		for (int i = 0; i < MAP_W; i++) {
			for (int j = 0; j < MAP_H; j++) {
				int tmp = _map[i][j];
				LayerColor *layer_block = nullptr;
				layer_block = LayerColor::create(mode[tmp], 128, 128);
				this->addChild(layer_block);
				layer_block->setPosition(i*128, j*128);
			}
		}
		route=Astar(MyVec2(0, 1), MyVec2(7, 3), _map);
		schedule(schedule_selector(HelloWorld::update), 1.0f, kRepeatForever, 0);
    return true;
}

void HelloWorld::update(float dt)
{
	if (!route.empty()) {
		auto tmp = route.top();
		route.pop();
		auto layer_block = LayerColor::create(Color4B::GREEN, 128, 128);
		this->addChild(layer_block);
		layer_block->setPosition(tmp.x * 128, tmp.y * 128);
	}
}








